package com.lwb.ztx.news.model;

import com.lwb.ztx.bean.NewsTopicBean;
import com.lwb.ztx.utils.LogUtils;
import com.lwb.ztx.utils.OkHttpUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/5/29.
 */
public class NewsTopicModelImpl implements NewsTopicModel {
    private OnNewsTopicLoadFinishListener listener;

    public NewsTopicModelImpl(OnNewsTopicLoadFinishListener listener) {
        this.listener = listener;
    }

    @Override
    public void loadTopicBean(String url) {
        OkHttpUtils.ResultCallback<String> loadNewsCallback = new OkHttpUtils.ResultCallback<String>() {
            @Override
            public void onSuccess(String response) {
                List<NewsTopicBean> beans = NewsJsonUtils.readJsonNewsTopicBeans(response);
                listener.onSuccess(beans);
                LogUtils.d(beans.toString());
            }

            @Override
            public void onFailure(Exception e) {
                listener.onFailure();
            }
        };
        OkHttpUtils.get(url, loadNewsCallback);
    }

    public interface OnNewsTopicLoadFinishListener {
        void onSuccess(List<NewsTopicBean> beans);
        void onFailure();
    }
}
